"use strict";
var _core = require("@pricking/core");
var _indexController = _interopRequireDefault(require("../base/IndexController"));
var _novelParser = _interopRequireDefault(require("../../services/novel-parser"));
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
    var desc = {};
    Object.keys(descriptor).forEach(function(key) {
        desc[key] = descriptor[key];
    });
    desc.enumerable = !!desc.enumerable;
    desc.configurable = !!desc.configurable;
    if ("value" in desc || desc.initializer) {
        desc.writable = true;
    }
    desc = decorators.slice().reverse().reduce(function(desc, decorator) {
        return decorator ? decorator(target, property, desc) || desc : desc;
    }, desc);
    if (context && desc.initializer !== void 0) {
        desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
        desc.initializer = undefined;
    }
    var own = Object.getOwnPropertyDescriptor(target, property);
    if (own && (own.get || own.set)) {
        delete desc.writable;
        delete desc.initializer;
    }
    if (desc.initializer === void 0) {
        Object.defineProperty(target, property, desc);
        desc = null;
    }
    return desc;
}
function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11;
var _dec12 = (0, _core).Controller('/v3/books');
let BookController = _class = _dec12(((_class = class BookController extends _indexController.default {
    async getBookInfo() {
        const { url  } = this.ctx.query;
        const result = await this.novelServices.getBookInfo(url);
        this.ctx.success(result);
    }
    async getBookInfos() {
        const { body: sources = []  } = this.ctx.request;
        this.validator.isNumber(sources.length, '不符合规则的参数');
        const results = await this.novelServices.getBookInfos(sources);
        this.ctx.success(results);
    }
    async searchBook() {
        const { keyword  } = this.ctx.query;
        this.validator.required(keyword, '请输入关键字');
        const result = await this.novelServices.searchBook(keyword);
        this.ctx.success(result);
    }
    constructor(...args){
        super(...args);
        this.novelServices = new _novelParser.default();
    }
}) || _class, _dec = (0, _core).Get('/info'), _dec1 = (0, _core).Description('查询书籍详情'), _dec2 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getBookInfo", [
    _dec,
    _dec1,
    _dec2,
    _dec3
], Object.getOwnPropertyDescriptor(_class.prototype, "getBookInfo"), _class.prototype), _dec4 = (0, _core).Post('/infos'), _dec5 = (0, _core).Description('批量查询书籍详情'), _dec6 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "getBookInfos", [
    _dec4,
    _dec5,
    _dec6,
    _dec7
], Object.getOwnPropertyDescriptor(_class.prototype, "getBookInfos"), _class.prototype), _dec8 = (0, _core).Get('/search'), _dec9 = (0, _core).Description('搜索'), _dec10 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec11 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", []), _applyDecoratedDescriptor(_class.prototype, "searchBook", [
    _dec8,
    _dec9,
    _dec10,
    _dec11
], Object.getOwnPropertyDescriptor(_class.prototype, "searchBook"), _class.prototype), _class)) || _class;
module.exports = BookController;
